#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2021, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: 0003.py
@time: 2021/9/7 14:23
@desc: https://leetcode-cn.com/problems/xoh6Oh/
'''
class Solution:
    def divide(self, a: int, b: int) -> int:
        INT_MIN, INT_MAX = -2**31+1, 2**31 - 1
        if a <= INT_MIN and b == -1:
            return INT_MIN

        sign = 1 if (a>0 and b>0) or (a<0 and b<0) else -1
        res = 0
        if a<0:
            a = -a
        if b<0:
            b = -b
        while a >= b:
            a -= b
            res += 1

        res = res if sign == 1 else -res

        return res

if __name__ == '__main__':
    s = Solution()
    r = s.divide(-2147483648, -1)
    print(r)